package com.karolak.stock.indicator;

import java.util.List;

import com.karolak.stock.data.DataManager;

public class IntegralInd extends Indicator {

	public IntegralInd(DataManager dataManager, int period, Indicator input) {
		super(dataManager, period, input);
		setName(String.format("%s%s%s", super.getName(), getInput().getName(), getPeriod()));
	}

	public double execute(double x) {
		List<Double> list = getDataManager().getData(getInput().getName(), getPeriod());
		if (list.isEmpty()) {
			return 0;
		}
		double sum = 0;
		for (double d : list) {
			sum = sum + d;
		}
		return sum/getPeriod();
	}
}
